function getOrder(data) {
    for (var i in data){
        var $order=$("<div class='order'></div>");
        $(".order_List").append($order);
        var $heard=$("<div class=\"order_heard\">\n" +
            "<p>\n" +
            "<div style=\"width: 20%\">用户名："+data[i].loginName+"</div>\n" +
            "<div style=\"width: 35%\">订单号："+data[i].serialNumber+"</div>\n" +
            "<div style=\"width: 28%\">地址："+data[i].userAddress+"</div>\n" +
            "<div style=\"width: 8%\">￥"+data[i].cost+"</div>\n" +
            "<div style=\"width: 5%\"><a class=\"updown\"><img style=\"width: 25px;height: 25px\" src=\"images/下拉-圆.png\" alt=\"\"/></a></div>\n" +
            "<div class=\"clear\" style=\"clear: both\"></div>\n" +
            "</p>\n" +
            "</div>\n");
        $($order).append($heard);
        var waresList=data[i].waresList;
        var tr="";
        for (var j in waresList) {
            tr=tr+"<tr>\n" +
                "<td>"+waresList[j].name+"</td>\n" +
                "<td><img width=\"100px\" height=\"100px\" src='images/"+waresList[j].fileName+"'alt=\"\"></td>\n" +
                "<td>"+waresList[j].quantity+"</td>\n" +
                "<td>￥"+waresList[j].price+"</td>\n" +
                "</tr>";
        }
        var table="<tr>\n" +
            "<th>商品名称</th>\n" +
            "<th>商品图片</th>\n" +
            "<th>数量</th>\n" +
            "<th>价格</th>\n" +
            "</tr>"+tr;
        var $body=$("<div class=\"order_body\"><table cellspacing='0'>"+table+"</table></div>");
        $($order).append($body);
    }
    //下拉按钮点击
    $(".updown").click(function () {
        $(this).parents(".order").find("table").toggle();
        if ($(this).find("img").attr('src') == "images/下拉-圆.png") {
            $(this).find("img").attr('src','images/上拉-圆.png');
        }else {
            $(this).find("img").attr('src','images/下拉-圆.png');
        }
    })
}
function orderList(pageNow){
    var condition=$("#condition").val();
    $(".order_List").empty();
    var user=JSON.parse(sessionStorage.getItem("user"));
    var page={
        pageSize:5,
        pageNow:pageNow,
    }
    $.ajax({
        url:"easybuy/getOrder?condition="+condition,
        type:"post",
        data:JSON.stringify(page),
        contentType:'application/json',
        async:false,
        dataType:"json",
        success:function (page) {
            getOrder(page.list);
            //翻页
            var $pages="";
            var black=parseInt(page.pageNow)-1<1?1:parseInt(page.pageNow)-1;
            $pages=$pages+"<a href='javascript:void(0)' class='p_pre' onclick='orderList("+black+")'>上一页</a>";
            if(page.pageNow>=5){
                $pages=$pages+"<a href='javascript:void(0)' onclick='orderList(1)'>1</a>...<a href='javascript:void(0)' onclick='orderList("+(parseInt(page.pageNow)-1)+")'>"+(parseInt(page.pageNow)-1)+"</a>";
            }else{
                for(i=1;i<page.pageNow;i++){
                    $pages=$pages+"<a href='javascript:void(0)' onclick='orderList("+i+")'>"+i+"</a>";
                }
            }
            $pages=$pages+"<a href='javascript:void(0)' class='cur'>"+page.pageNow+"</a>";
            if(page.pageMax-page.pageNow>=4){
                $pages=$pages+"<a href='javascript:void(0)' onclick='orderList("+(parseInt(page.pageNow)+1)+")'>"+(parseInt(page.pageNow)+1)+"</a>...<a href='javascript:void(0)' onclick='orderList("+page.pageMax+")'>"+page.pageMax+"</a>";
            }else{
                for(i=page.pageNow+1;i<=page.pageMax;i++){
                    $pages=$pages+"<a href='javascript:void(0)' onclick='orderList("+i+")'>"+i+"</a>";
                }
            }
            var next=parseInt(page.pageNow)+1>parseInt(page.pageMax)?parseInt(page.pageMax):parseInt(page.pageNow)+1;
            $pages=$pages+"<a href='javascript:void(0)' class='p_pre' onclick='orderList("+next+")'>下一页</a>";
            $(".pages").html($pages);
        }
    })
}
$(function () {
    orderList(1);
})
